package io.hx.modules.hos.service.impl;

import io.hx.modules.patient.dao.PatientUserDao;
import io.hx.modules.sys.dao.SysDeptDao;
import io.hx.modules.sys.dao.SysUserDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.hx.common.utils.PageUtils;
import io.hx.common.utils.Query;

import io.hx.modules.hos.dao.AppointmentDao;
import io.hx.modules.hos.entity.AppointmentEntity;
import io.hx.modules.hos.service.AppointmentService;


@Service("appointmentService")
public class AppointmentServiceImpl extends ServiceImpl<AppointmentDao, AppointmentEntity> implements AppointmentService {
    @Autowired
    AppointmentDao appointmentDao;
    @Autowired
    PatientUserDao patientUserDao;
    @Autowired
    SysUserDao sysUserDao;
    @Autowired
    SysDeptDao sysDeptDao;

    @Override
    public PageUtils queryPage(Map<String, Object> params) {

        IPage<AppointmentEntity> page = this.page(
                new Query<AppointmentEntity>().getPage(params),
                new QueryWrapper<AppointmentEntity>().between("appointment_status",0,1).orderByAsc("appointment_status")
        );
        for (AppointmentEntity record : page.getRecords()) {
            record.setUser(patientUserDao.selectById(record.getUserId()));
            record.setSysUser(sysUserDao.selectById(record.getSysUserId()));
            record.setSysDeptEntity(sysDeptDao.selectById(record.getOutpatientsId()));
        }
        return new PageUtils(page);
    }
    @Override
    public Integer queryPatientAll() {
        return appointmentDao.queryPatientAll();
    }

    @Override
    public List<Integer> queryFurtherAll() {
        return appointmentDao.queryFurtherAll();
    }

    @Override
    public List<Integer> queryFirstAll() {
        return appointmentDao.queryFirstAll();
    }

    @Override
    public List<Integer> queryVisitsAll() {
        return appointmentDao.queryVisitsAll();
    }

    @Override
    public List<Integer> queryAgeAll() {
        return appointmentDao.queryAgeAll();
    }

    @Override
    public List<Integer> queryGenderAll() {
        return appointmentDao.queryGenderAll();
    }

}
